<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */
$basedir = dirname(__FILE__);

require_once $basedir . '/../../../classes/mm/discovery.php';

require_once $basedir . '/../../../classes/mm/logger/interface.php';
require_once $basedir . '/../../../classes/mm/httpclient/interface.php';

require_once $basedir . '/../../../classes/mm/logger.php';
require_once $basedir . '/../../../classes/mm/httpclient.php';

require_once $basedir . '/../../../classes/mm/xrd.php';
require_once $basedir . '/../../../classes/mm/atom.php';

require_once $basedir . '/../../../classes/mm/xml/element/builder/interface.php';
require_once $basedir . '/../../../classes/mm/xml/element/builder/abstract.php';
require_once $basedir . '/../../../classes/mm/xml/element/abstract.php';
require_once $basedir . '/../../../classes/mm/xml/element/parent.php';
require_once $basedir . '/../../../classes/mm/xml/element/parser.php';

require_once $basedir . '/../../../classes/mm/xrd/element/hostmeta.php';
require_once $basedir . '/../../../classes/mm/xrd/element/link.php';
require_once $basedir . '/../../../classes/mm/xrd/element/host.php';
require_once $basedir . '/../../../classes/mm/xrd/element/hostmeta/builder.php';

require_once $basedir . '/../../../classes/mm/xrd.php';
require_once $basedir . '/../../../classes/mm/atom.php';

require_once $basedir . '/../../../classes/mm/xml/element/builder/interface.php';
require_once $basedir . '/../../../classes/mm/xml/element/builder/abstract.php';
require_once $basedir . '/../../../classes/mm/xml/element/abstract.php';
require_once $basedir . '/../../../classes/mm/xml/element/parent.php';
require_once $basedir . '/../../../classes/mm/xml/element/parser.php';

require_once $basedir . '/../../../classes/mm/xrd/element/lrdd.php';
require_once $basedir . '/../../../classes/mm/xrd/element/alias.php';
require_once $basedir . '/../../../classes/mm/xrd/element/subject.php';
require_once $basedir . '/../../../classes/mm/xrd/element/link.php';
require_once $basedir . '/../../../classes/mm/xrd/element/lrdd/builder.php';

require_once $basedir . '/../../../classes/mm/xml/element/builder/interface.php';
require_once $basedir . '/../../../classes/mm/xml/element/builder/abstract.php';
require_once $basedir . '/../../../classes/mm/xml/element/abstract.php';

require_once $basedir . '/../../../classes/mm/atom.php';
require_once $basedir . '/../../../classes/mm/xml/element/parent.php';
require_once $basedir . '/../../../classes/mm/atom/element/feed.php';
require_once $basedir . '/../../../classes/mm/atom/element/generator.php';
require_once $basedir . '/../../../classes/mm/atom/element/id.php';
require_once $basedir . '/../../../classes/mm/atom/element/link.php';
require_once $basedir . '/../../../classes/mm/atom/element/title.php';
require_once $basedir . '/../../../classes/mm/atom/element/subtitle.php';
require_once $basedir . '/../../../classes/mm/atom/element/updated.php';
require_once $basedir . '/../../../classes/mm/atom/element/logo.php';
require_once $basedir . '/../../../classes/mm/atom/element/name.php';
require_once $basedir . '/../../../classes/mm/atom/element/uri.php';
require_once $basedir . '/../../../classes/mm/atom/element/entry.php';
require_once $basedir . '/../../../classes/mm/atom/element/content.php';

require_once $basedir . '/../../../classes/mm/atom/element/author.php';
require_once $basedir . '/../../../classes/mm/atom/element/author/builder.php';

require_once $basedir . '/../../../classes/mm/atom/element/activitystream.php';
require_once $basedir . '/../../../classes/mm/atom/element/activitystream/subject.php';
require_once $basedir . '/../../../classes/mm/atom/element/activitystream/objecttype.php';
require_once $basedir . '/../../../classes/mm/atom/element/activitystream/verb.php';
require_once $basedir . '/../../../classes/mm/atom/element/activitystream/subject/builder.php';

require_once $basedir . '/../../../classes/mm/atom/element/activitystream/object/builder.php';
require_once $basedir . '/../../../classes/mm/atom/element/activitystream/object.php';

require_once $basedir . '/../../../classes/mm/atom/element/poco/displayname.php';

require_once $basedir . '/../../../classes/mm/atom/element/entry/builder.php';

require_once $basedir . '/../../../classes/mm/xml/element/parser.php';

require_once $basedir . '/../../../classes/mm/atom/element/feed/builder.php';


class Mm_Discoverytest extends PHPUnit_Framework_TestCase {
    public function testConstructorOfDiscoveryWithJid() {
        $jid = "acct:tuomas@boobies.com";
        $object = new Mm_Discovery($jid);
        $this->assertEquals("Mm_Discovery", get_class($object));
    }
   
    public function testDomainAndUri() {
        $jid = "tuomas@boobies.com";
        $object = new Mm_Discovery($jid);
        $this->assertEquals("acct:tuomas@boobies.com", $object->getUri());
        $this->assertEquals("boobies.com", $object->getDomain());
        
        $jid = "acct:tuomas@boobies.com";
        $object = new Mm_Discovery($jid);
        $this->assertEquals("acct:tuomas@boobies.com", $object->getUri());
        $this->assertEquals("boobies.com", $object->getDomain());
        
        $jid = "http://boobies.com/tuomas";
        $object = new Mm_Discovery($jid);
        $this->assertEquals("http://boobies.com/tuomas", $object->getUri());
        $this->assertEquals("boobies.com", $object->getDomain());
        
        $jid = "https://boobies.com/tuomas";
        $object = new Mm_Discovery($jid);
        $this->assertEquals("https://boobies.com/tuomas", $object->getUri());
        $this->assertEquals("boobies.com", $object->getDomain());
    }
    
    public function testDiscoveryLrdd() {
        $jid = "tuomas@boobies.com";
        
        $mock = $this->getMock('Mm_Discovery', array('fetchURL'), array($jid));
        
        $expectedHostMetaXMLFail = '';
        $expectedHostMetaXMLSuccess = array('body' => '<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:hm="http://host-meta.net/xrd/1.0">
  <hm:Host>boobies.com</hm:Host>
  <Link rel="lrdd" template="http://boobs.com/xrd?uri={uri}">
    <Title>Resource Descriptor</Title>
  </Link>
</XRD>
');
        
        $expectedLrddXML = array('body' => '<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
  <Subject>http://identi.ca/user/37</Subject>
  <Alias>http://identi.ca/user/37</Alias>
  <Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="http://identi.ca/user/37"/>
  <Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="http://identi.ca/api/statuses/user_timeline/37.atom"/>
  <Link rel="http://microformats.org/profile/hcard" type="text/html" href="http://identi.ca/rejon/hcard"/>
  <Link rel="http://gmpg.org/xfn/11" type="text/html" href="http://identi.ca/user/37"/>
  <Link rel="describedby" type="application/rdf+xml" href="http://identi.ca/rejon/foaf"/>
  <Link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://identi.ca/main/salmon/user/37"/>
  <Link rel="http://salmon-protocol.org/ns/salmon-mention" href="http://identi.ca/main/salmon/user/37"/>
  <Link rel="magic-public-key" href="data:application/magic-public-key,RSA.gKnrPANtKsidF7I7gvAev0HJ8kKNLrLm_rmPlf0M_g4f5ukqHiMmcCl59qN3u2YGr5Z1ba2SvT7EYWNTaF4AxZCmNR3MRKYVuI2EL7xQZiz1KcWurkiXI-Plm0VbatB30Dg1gosRtWUfjZqWJTJFQyKZXt7NEIhMsfzGNhsuxzk=.AQAB"/>
  <Link rel="http://ostatus.org/schema/1.0/subscribe" template="http://identi.ca/main/ostatussub?profile={uri}"/>
</XRD>
');
        $expectedAtomFeed = array('body' => '<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">
 <generator uri="http://status.net" version="0.9.3">StatusNet</generator>
 <id>http://identi.ca/api/statuses/user_timeline/37.atom</id>
 <title>rejon timeline</title>
 <subtitle>Updates from rejon on Identi.ca!</subtitle>
 <logo>http://avatar.identi.ca/37-96-20100311063213.png</logo>
 <updated>2010-08-10T09:32:44+00:00</updated>
<author>
 <name>rejon</name>
 <uri>http://identi.ca/user/37</uri>
</author>
 <link href="http://identi.ca/rejon" rel="alternate" type="text/html"/>
 <link href="http://identi.ca/main/sup#37" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
 <link href="http://identi.ca/main/push/hub" rel="hub"/>
 <link href="http://identi.ca/main/salmon/user/37" rel="http://salmon-protocol.org/ns/salmon-replies"/>
 <link href="http://identi.ca/main/salmon/user/37" rel="http://salmon-protocol.org/ns/salmon-mention"/>
 <link href="http://identi.ca/api/statuses/user_timeline/37.atom" rel="self" type="application/atom+xml"/>
<activity:subject>
 <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
 <id>http://identi.ca/user/37</id>
 <title>Jon Phillips</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/rejon"/>
 <link rel="avatar" type="image/png" media:width="192" media:height="192" href="http://avatar.identi.ca/37-192-20100311063213.png"/>
 <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://avatar.identi.ca/37-96-20100311063213.png"/>
 <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://avatar.identi.ca/37-48-20100311063213.png"/>
 <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://avatar.identi.ca/37-24-20100311063213.png"/>
<poco:preferredUsername>rejon</poco:preferredUsername>
<poco:displayName>Jon Phillips</poco:displayName>
<poco:note>http://rejon.org/bio</poco:note>
<poco:address>
 <poco:formatted>San Francisco, USA + Beijing, China</poco:formatted>
</poco:address>
<poco:urls>
 <poco:type>homepage</poco:type>
 <poco:value>http://rejon.org</poco:value>
 <poco:primary>true</poco:primary>
</poco:urls>
</activity:subject>
<entry>
 <title>Did some rapidfire planning with @evanpro today...time to max this puppy out...hardcore august, fall and spring max out :)</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45644215"/>
 <id>http://identi.ca/notice/45644215</id>
 <published>2010-08-10T06:06:14+00:00</published>
 <updated>2010-08-10T06:06:14+00:00</updated>
 <statusnet:notice_info local_id="45644215" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45309395"/>
 <content type="html">Did some rapidfire planning with @evanpro today...time to max this puppy out...hardcore august, fall and spring max out :)</content>
</entry>
<entry>
 <title>Bring da pain. I\'m REcharged!</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45644179"/>
 <id>http://identi.ca/notice/45644179</id>
 <published>2010-08-10T06:05:38+00:00</published>
 <updated>2010-08-10T06:05:38+00:00</updated>
 <statusnet:notice_info local_id="45644179" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45309359"/>
 <content type="html">Bring da pain. I\'m REcharged!</content>
</entry>
<entry>
 <title>How is everyone doing out there?</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45608813"/>
 <id>http://identi.ca/notice/45608813</id>
 <published>2010-08-09T21:37:58+00:00</published>
 <updated>2010-08-09T21:37:58+00:00</updated>
 <statusnet:notice_info local_id="45608813" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45274892"/>
 <content type="html">How is everyone doing out there?</content>
</entry>
<entry>
 <title>Updating with @mlinksva, meeting @davelab6@identi.ca with  at @creativecommons then to !StatusNet !SF...</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45608277"/>
 <id>http://identi.ca/notice/45608277</id>
 <published>2010-08-09T21:31:46+00:00</published>
 <updated>2010-08-09T21:31:46+00:00</updated>
 <statusnet:notice_info local_id="45608277" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45274377"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/8"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/13586"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/14625"/>
 <link rel="ostatus:attention" href="http://identi.ca/group/242/id"/>
 <content type="html">Updating with @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/8&quot; class=&quot;url&quot; title=&quot;Mike Linksvayer&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;mlinksva&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;, meeting @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/14625&quot; class=&quot;url&quot; title=&quot;Dave Crossland&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;davelab6&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;@identi.ca with  at @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/13586&quot; class=&quot;url&quot; title=&quot;Creative Commons&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;creativecommons&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; then to !StatusNet !&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/group/242/id&quot; class=&quot;url&quot; title=&quot;San Francisco (sfo)&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;SF&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;...</content>
 <category term="sf"></category>
 <category term="statusnet"></category>
</entry>
<entry>
 <title>I know this isn\'t the year of IDEA, ever other year, but! #IDEA2010. Get chinese pirate software makers to distribute inkscape...</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45596006"/>
 <id>http://identi.ca/notice/45596006</id>
 <published>2010-08-09T18:59:45+00:00</published>
 <updated>2010-08-09T18:59:45+00:00</updated>
 <statusnet:notice_info local_id="45596006" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45262515"/>
 <content type="html">I know this isn\'t the year of IDEA, ever other year, but! #&lt;span class=&quot;tag&quot;&gt;&lt;a href=&quot;http://identi.ca/tag/idea2010&quot; rel=&quot;tag&quot;&gt;IDEA2010.&lt;/a&gt;&lt;/span&gt; Get chinese pirate software makers to distribute inkscape...</content>
 <category term="idea2010"></category>
</entry>
<entry>
 <title>Subscribed to TheRealDivaTV http://ping.fm/AIyzY</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45551465"/>
 <id>http://identi.ca/notice/45551465</id>
 <published>2010-08-09T10:20:23+00:00</published>
 <updated>2010-08-09T10:20:23+00:00</updated>
 <statusnet:notice_info local_id="45551465" source="&lt;a href=&quot;http://ping.fm/&quot; rel=&quot;nofollow&quot;&gt;Ping.fm&lt;/a&gt;" source_link="http://ping.fm/"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45219144"/>
 <content type="html">Subscribed to TheRealDivaTV &lt;a href=&quot;http://ping.fm/AIyzY&quot; title=&quot;http://www.youtube.com/user/TheRealDivaTV?feature=autoshare&quot; rel=&quot;external&quot;&gt;http://ping.fm/AIyzY&lt;/a&gt;</content>
</entry>
<entry>
 <title>♺ @andyfitz: Confession:   I\'m a skeptic.  Wish I wasn\'t but I dont wish</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45542045"/>
 <id>http://identi.ca/notice/45542045</id>
 <published>2010-08-09T08:47:39+00:00</published>
 <updated>2010-08-09T08:47:39+00:00</updated>
 <statusnet:notice_info local_id="45542045" source="&lt;a href=&quot;http://launchpad.net/gwibber&quot; rel=&quot;nofollow&quot;&gt;Gwibber&lt;/a&gt;" source_link="http://launchpad.net/gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45209814"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/17827"/>
 <content type="html">♺ @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/17827&quot; class=&quot;url&quot; title=&quot;Andy Fitzsimon&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;andyfitz&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;: Confession:   I\'m a skeptic.  Wish I wasn\'t but I dont wish</content>
</entry>
<entry>
 <title>Pee-wee\'s Big Adventure - Tequila http://ping.fm/FOEFh</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45495968"/>
 <id>http://identi.ca/notice/45495968</id>
 <published>2010-08-08T22:17:22+00:00</published>
 <updated>2010-08-08T22:17:22+00:00</updated>
 <statusnet:notice_info local_id="45495968" source="&lt;a href=&quot;http://ping.fm/&quot; rel=&quot;nofollow&quot;&gt;Ping.fm&lt;/a&gt;" source_link="http://ping.fm/"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45164547"/>
 <content type="html">Pee-wee\'s Big Adventure - Tequila &lt;a href=&quot;http://ping.fm/FOEFh&quot; title=&quot;http://www.youtube.com/watch?v=BodXwAYeTfM&amp;amp;feature=autoshare&quot; rel=&quot;external&quot;&gt;http://ping.fm/FOEFh&lt;/a&gt;</content>
</entry>
</feed>
');
        
        $mock->expects($this->at(0))
             ->method('fetchURL')
             ->with($this->equalTo('https://boobies.com/.well-known/host-meta'))
             ->will($this->returnValue($expectedHostMetaXMLFail));
        $mock->expects($this->at(1))
             ->method('fetchURL')
             ->with($this->equalTo('http://boobies.com/.well-known/host-meta'))
             ->will($this->returnValue($expectedHostMetaXMLSuccess));
        $mock->expects($this->at(2))
             ->method('fetchURL')
             ->with($this->equalTo('http://boobs.com/xrd?uri=acct%3Atuomas%40boobies.com'))
             ->will($this->returnValue($expectedLrddXML));
        $mock->expects($this->at(3))
             ->method('fetchURL')
             ->with($this->equalTo('http://identi.ca/api/statuses/user_timeline/37.atom'))
             ->will($this->returnValue($expectedAtomFeed));   
             
        $this->assertEquals(true, $mock->discover());
    }
    
    public function testDiscoveryNoLrdd() {
        $jid = "http://identi.ca/tkoski";
        
        $mock = $this->getMock('Mm_Discovery', array('fetchURL'), array($jid));
        
        $expectedHostMetaXMLFail = '';
        $expectedHostMetaXMLSuccess = array('body' => '');
        
        $expectedLrddXML = array('body' => '');
        
        $expectedProfilePage = array('body' => '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>Tuomas Koski (tkoski)  - Identi.ca</title>
  <link rel="shortcut icon" href="http://identi.ca/favicon.ico"/>
  <link rel="stylesheet" type="text/css" href="http://theme.status.net/0.9.4/identica/css/display.css?version=0.9.4" media="screen, projection, tv, print"/>
  <style type="text/css">span.rtl {display:block;direction:rtl;text-align:right;float:right;width:490px;} .notice .author {float:left}</style>
  <link rel="stylesheet" type="text/css" href="http://identi.ca/plugins/Realtime/realtimeupdate.css?version=0.9.4" media="screen, projection, tv"/>
  <link rel="stylesheet" type="text/css" href="http://identi.ca/plugins/OStatus/theme/base/css/ostatus.css?version=0.9.4" media=""/>
  <!--[if IE]><link rel="stylesheet" type="text/css" href="http://theme.status.net/0.9.4/base/css/ie.css?version=0.9.4" /><![endif]-->
  <!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="http://theme.status.net/0.9.4/base/css/ie6.css?version=0.9.4" /><![endif]-->
  <!--[if IE]><link rel="stylesheet" type="text/css" href="http://theme.status.net/0.9.4/identica/css/ie.css?version=0.9.4" /><![endif]-->
  <link rel="search" type="application/opensearchdescription+xml" href="http://identi.ca/opensearch/people" title="Identi.ca People Search"/>
  <link rel="search" type="application/opensearchdescription+xml" href="http://identi.ca/opensearch/notice" title="Identi.ca Notice Search"/>
  <link rel="alternate" href="http://identi.ca/tkoski/rss" type="application/rdf+xml" title="Notice feed for tkoski (RSS 1.0)"/>
  <link rel="alternate" href="http://identi.ca/api/statuses/user_timeline/52467.rss" type="application/rss+xml" title="Notice feed for tkoski (RSS 2.0)"/>
  <link rel="alternate" href="http://identi.ca/api/statuses/user_timeline/52467.atom" type="application/atom+xml" title="Notice feed for tkoski (Atom)"/>
  <link rel="meta" href="http://identi.ca/tkoski/foaf" type="application/rdf+xml" title="FOAF for tkoski"/>
  <meta http-equiv="X-XRDS-Location" content="http://identi.ca/tkoski/xrds"/>
  <meta name="description" content="Happy Finnish programmer."/>
  <meta name="microid" content="mailto+http:sha1:31fbcfa1f4c9251afd6c8344b60f54007f514611"/>
  <meta name="microid" content="xmpp+http:sha1:76426ef40d8b422db8a66060c736f081d9bfb92a"/>
  <link rel="microsummary" href="http://identi.ca/tkoski/microsummary"/>
  <link rel="EditURI" type="application/rsd+xml" href="http://identi.ca/tkoski/rsd.xml"/>
  <link rel="openid2.provider" href="http://identi.ca/main/openidserver"/>
  <link rel="openid2.local_id" href="http://identi.ca/tkoski"/>
  <link rel="openid.server" href="http://identi.ca/main/openidserver"/>
  <link rel="openid.delegate" href="http://identi.ca/tkoski"/>
</head>
 <body id="showstream"></body></html>
 ');
        
        $expectedAtomFeed = array('body' => '<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">
 <generator uri="http://status.net" version="0.9.3">StatusNet</generator>
 <id>http://identi.ca/api/statuses/user_timeline/37.atom</id>
 <title>rejon timeline</title>
 <subtitle>Updates from rejon on Identi.ca!</subtitle>
 <logo>http://avatar.identi.ca/37-96-20100311063213.png</logo>
 <updated>2010-08-10T09:32:44+00:00</updated>
<author>
 <name>rejon</name>
 <uri>http://identi.ca/user/37</uri>
</author>
 <link href="http://identi.ca/rejon" rel="alternate" type="text/html"/>
 <link href="http://identi.ca/main/sup#37" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
 <link href="http://identi.ca/main/push/hub" rel="hub"/>
 <link href="http://identi.ca/main/salmon/user/37" rel="http://salmon-protocol.org/ns/salmon-replies"/>
 <link href="http://identi.ca/main/salmon/user/37" rel="http://salmon-protocol.org/ns/salmon-mention"/>
 <link href="http://identi.ca/api/statuses/user_timeline/37.atom" rel="self" type="application/atom+xml"/>
<activity:subject>
 <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
 <id>http://identi.ca/user/37</id>
 <title>Jon Phillips</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/rejon"/>
 <link rel="avatar" type="image/png" media:width="192" media:height="192" href="http://avatar.identi.ca/37-192-20100311063213.png"/>
 <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://avatar.identi.ca/37-96-20100311063213.png"/>
 <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://avatar.identi.ca/37-48-20100311063213.png"/>
 <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://avatar.identi.ca/37-24-20100311063213.png"/>
<poco:preferredUsername>rejon</poco:preferredUsername>
<poco:displayName>Jon Phillips</poco:displayName>
<poco:note>http://rejon.org/bio</poco:note>
<poco:address>
 <poco:formatted>San Francisco, USA + Beijing, China</poco:formatted>
</poco:address>
<poco:urls>
 <poco:type>homepage</poco:type>
 <poco:value>http://rejon.org</poco:value>
 <poco:primary>true</poco:primary>
</poco:urls>
</activity:subject>
<entry>
 <title>Did some rapidfire planning with @evanpro today...time to max this puppy out...hardcore august, fall and spring max out :)</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45644215"/>
 <id>http://identi.ca/notice/45644215</id>
 <published>2010-08-10T06:06:14+00:00</published>
 <updated>2010-08-10T06:06:14+00:00</updated>
 <statusnet:notice_info local_id="45644215" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45309395"/>
 <content type="html">Did some rapidfire planning with @evanpro today...time to max this puppy out...hardcore august, fall and spring max out :)</content>
</entry>
<entry>
 <title>Bring da pain. I\'m REcharged!</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45644179"/>
 <id>http://identi.ca/notice/45644179</id>
 <published>2010-08-10T06:05:38+00:00</published>
 <updated>2010-08-10T06:05:38+00:00</updated>
 <statusnet:notice_info local_id="45644179" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45309359"/>
 <content type="html">Bring da pain. I\'m REcharged!</content>
</entry>
<entry>
 <title>How is everyone doing out there?</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45608813"/>
 <id>http://identi.ca/notice/45608813</id>
 <published>2010-08-09T21:37:58+00:00</published>
 <updated>2010-08-09T21:37:58+00:00</updated>
 <statusnet:notice_info local_id="45608813" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45274892"/>
 <content type="html">How is everyone doing out there?</content>
</entry>
<entry>
 <title>Updating with @mlinksva, meeting @davelab6@identi.ca with  at @creativecommons then to !StatusNet !SF...</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45608277"/>
 <id>http://identi.ca/notice/45608277</id>
 <published>2010-08-09T21:31:46+00:00</published>
 <updated>2010-08-09T21:31:46+00:00</updated>
 <statusnet:notice_info local_id="45608277" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45274377"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/8"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/13586"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/14625"/>
 <link rel="ostatus:attention" href="http://identi.ca/group/242/id"/>
 <content type="html">Updating with @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/8&quot; class=&quot;url&quot; title=&quot;Mike Linksvayer&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;mlinksva&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;, meeting @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/14625&quot; class=&quot;url&quot; title=&quot;Dave Crossland&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;davelab6&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;@identi.ca with  at @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/13586&quot; class=&quot;url&quot; title=&quot;Creative Commons&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;creativecommons&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; then to !StatusNet !&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/group/242/id&quot; class=&quot;url&quot; title=&quot;San Francisco (sfo)&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;SF&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;...</content>
 <category term="sf"></category>
 <category term="statusnet"></category>
</entry>
<entry>
 <title>I know this isn\'t the year of IDEA, ever other year, but! #IDEA2010. Get chinese pirate software makers to distribute inkscape...</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45596006"/>
 <id>http://identi.ca/notice/45596006</id>
 <published>2010-08-09T18:59:45+00:00</published>
 <updated>2010-08-09T18:59:45+00:00</updated>
 <statusnet:notice_info local_id="45596006" source="gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45262515"/>
 <content type="html">I know this isn\'t the year of IDEA, ever other year, but! #&lt;span class=&quot;tag&quot;&gt;&lt;a href=&quot;http://identi.ca/tag/idea2010&quot; rel=&quot;tag&quot;&gt;IDEA2010.&lt;/a&gt;&lt;/span&gt; Get chinese pirate software makers to distribute inkscape...</content>
 <category term="idea2010"></category>
</entry>
<entry>
 <title>Subscribed to TheRealDivaTV http://ping.fm/AIyzY</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45551465"/>
 <id>http://identi.ca/notice/45551465</id>
 <published>2010-08-09T10:20:23+00:00</published>
 <updated>2010-08-09T10:20:23+00:00</updated>
 <statusnet:notice_info local_id="45551465" source="&lt;a href=&quot;http://ping.fm/&quot; rel=&quot;nofollow&quot;&gt;Ping.fm&lt;/a&gt;" source_link="http://ping.fm/"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45219144"/>
 <content type="html">Subscribed to TheRealDivaTV &lt;a href=&quot;http://ping.fm/AIyzY&quot; title=&quot;http://www.youtube.com/user/TheRealDivaTV?feature=autoshare&quot; rel=&quot;external&quot;&gt;http://ping.fm/AIyzY&lt;/a&gt;</content>
</entry>
<entry>
 <title>♺ @andyfitz: Confession:   I\'m a skeptic.  Wish I wasn\'t but I dont wish</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45542045"/>
 <id>http://identi.ca/notice/45542045</id>
 <published>2010-08-09T08:47:39+00:00</published>
 <updated>2010-08-09T08:47:39+00:00</updated>
 <statusnet:notice_info local_id="45542045" source="&lt;a href=&quot;http://launchpad.net/gwibber&quot; rel=&quot;nofollow&quot;&gt;Gwibber&lt;/a&gt;" source_link="http://launchpad.net/gwibber"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45209814"/>
 <link rel="ostatus:attention" href="http://identi.ca/user/17827"/>
 <content type="html">♺ @&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://identi.ca/user/17827&quot; class=&quot;url&quot; title=&quot;Andy Fitzsimon&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;andyfitz&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;: Confession:   I\'m a skeptic.  Wish I wasn\'t but I dont wish</content>
</entry>
<entry>
 <title>Pee-wee\'s Big Adventure - Tequila http://ping.fm/FOEFh</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/45495968"/>
 <id>http://identi.ca/notice/45495968</id>
 <published>2010-08-08T22:17:22+00:00</published>
 <updated>2010-08-08T22:17:22+00:00</updated>
 <statusnet:notice_info local_id="45495968" source="&lt;a href=&quot;http://ping.fm/&quot; rel=&quot;nofollow&quot;&gt;Ping.fm&lt;/a&gt;" source_link="http://ping.fm/"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/45164547"/>
 <content type="html">Pee-wee\'s Big Adventure - Tequila &lt;a href=&quot;http://ping.fm/FOEFh&quot; title=&quot;http://www.youtube.com/watch?v=BodXwAYeTfM&amp;amp;feature=autoshare&quot; rel=&quot;external&quot;&gt;http://ping.fm/FOEFh&lt;/a&gt;</content>
</entry>
</feed>
');
        
        $mock->expects($this->at(0))
             ->method('fetchURL')
             ->with($this->equalTo('http://identi.ca/.well-known/host-meta'))
             ->will($this->returnValue($expectedHostMetaXMLFail));
        $mock->expects($this->at(1))
             ->method('fetchURL')
             ->with($this->equalTo('https://identi.ca/.well-known/host-meta'))
             ->will($this->returnValue($expectedHostMetaXMLSuccess));
        $mock->expects($this->at(2))
             ->method('fetchURL')
             ->with($this->equalTo($jid))
             ->will($this->returnValue($expectedProfilePage));
        $mock->expects($this->at(3))
             ->method('fetchURL')
             ->with($this->equalTo('http://identi.ca/api/statuses/user_timeline/52467.atom'))
             ->will($this->returnValue($expectedAtomFeed));   
             
        $this->assertEquals(true, $mock->discover());
    }
}